$(document).ready(function() {
	 var parms ={};
	 ajaxDrawTable(parms);
	});

ajaxDrawTable = function(parms) {
	   var  org_id = $("#org_id").val();
	   var  url = baseURL+"/api/role/listStatus/"+org_id;
	   if(parms!=null){
		   var index =0;
		   for(var key in parms){
			   if(index==0){
             url =  url+"?"+key+"="+ parms[key];
			   }else{
				    url =  url+"&"+key+"="+ parms[key];
			   }
		   }
	   }
		$.ajax({ 
		    url: url,
		    type: "get",
		    dataType: "json",
		    timeout : 30000,
		    success: function(data) {
							var obj = data; 
							data=obj.results;
							dataSet = [];
							//json重构数组对象 
							$.each(data,function(i,val){
								dataSet[i]=[]
								dataSet[i][0]=data[i].id
								dataSet[i][1]=data[i].name
								dataSet[i][2]=data[i].code
								dataSet[i][3]=data[i].descn
								dataSet[i][4]=data[i].isChecked
							});
							drawTable(dataSet);
		     },
		    cache: false,
		    timeout: 5000,
		    error: function() {
		        layer.msg("数据加载超时");
		    }
		  }); 
	}

drawTable = function(dataSet) {
	   registerMainTable = $('.table-sort').dataTable( {
			"data": dataSet,
			"bPaginate":false,
			"bProcessing":true,
			"sPaginationType":'full_numbers',
			"bSort": false,             
			"bFilter": false, 
			"aoColumnDefs": [                 
	                          {               
	                            "render": function (data, type, full){  
	                            	var html = ''
	                            	if(!full[4]){
	                            		html = '<input type="checkbox" id="CheckUser" name="SelectedRoleId"  class="btn btn-danger radius" value="' + full[0]+ '"/>'
	                            	}else{
	                            		html = '<input type="checkbox" id="CheckUser" checked="checked" name="SelectedRoleId"  class="btn btn-danger radius" value="' + full[0]+ '"/>'
	                            	}
	                                return html;   
	                              },
	                            "targets": 0 
	                           },
	                          { "bSearchable": false, "bVisible": false, "aTargets": [4] }
	                        ] 
		});
	};
	
	_submit = function() {
		var objs = $('input[name=SelectedRoleId]');
		var ids = []; 
		var j=0;
		$.each(objs, function(i, val) {
			if (objs[i].checked) {
				if (objs[i].value != "") {
					ids[j]=objs[i].value;j++;
				}
			}
		});
		/* if (ids.length==0) {
			layer.msg("请选择删除项！");
			return false;
		} */
		var  org_id = $("#org_id").val();
		var url  = baseURL+'/api/role/grantRoles2Org/'+org_id;
		$.ajax({
			type : "post",
			url : url,
			dataType : "json",
			contentType : "application/json",
			data : JSON.stringify(ids),
			success : function(result) {
				if (!result.flag) {
					layer.msg("删除失败！原因：" + result.message);
					return;
				} else {
					layer.msg("设置成功！");
					location.reload();
				}
			}
		});
		return true;
	}
